<html><head><link href="../../../css-stylesheets/elucidator/program.css" rel="stylesheet" title="program" type="text/css" /> <title>Source file</title></head><body bgcolor="#ffffff" text="#000000" link="#000000" vlink="#000000"><font size="2"><pre><span class="comment">; The LAML library and programs written by Kurt Normark, Aalborg University, Denmark.
; Copyright (C) 1999  Kurt Normark.
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</span><br />

<div class="schemedoc-abstract-comment">;;;; This library provides a number of functions that reads a string from a text file,
;;;; and functions which write a string to a text file.
;;;; In particular the library supports very useful functions that read selected parts of a text file to strings.&lt;p&gt;
;;;; The main functions are: read-text-file and write-text-file.
;;;; The selective reading functions are read-text-file-between-marks and read-text-file-including-marks.
;;;; .title Reference Manual of the Text File Reading and Writing Library</div>
<span class="comment">; -----------------------------------------------------------------------------</span><br />
<a name="read-text-file"></a><div class="schemedoc-section-comment">;;; Reading stuff. </div>
<a name="read-text-file"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(read-text-file file-name)</span>
  <div class="schemedoc-definition-comment">;; Return the textual contents of file-name, as a string</div> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">ip</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX444" title="R5RS Scheme form">open-input-file</a> file-name))
        (<span class="local-name-binding">res</span> (<a class="applied-name" href="file-read-1.html#read-text-file-from-input-port" title="file-read">read-text-file-from-input-port</a> ip)))
     (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX446" title="R5RS Scheme form">close-input-port</a> ip)
     res))

<a name="file-chunck"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">file-chunck</span> 1000)

<a name="read-text-file-from-input-port"></a><span><a href="../file-read.html#read-text-file-from-input-port"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(read-text-file-from-input-port input-port)</span>
  <div class="schemedoc-definition-comment">;; Return the textual contents of input-port, as a string</div> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">res</span> (<a class="applied-name" href="file-read-1.html#read-text-file-portion" title="file-read">read-text-file-portion</a> input-port <a class="applied-name" href="file-read-1.html#file-chunck" title="file-read">file-chunck</a>)))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX455" title="R5RS Scheme form">eof-object?</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX453" title="R5RS Scheme form">peek-char</a> input-port)))
      (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> res (<a class="applied-name" href="file-read-1.html#read-text-file-from-input-port" title="file-read">read-text-file-from-input-port</a> input-port))
      res)))

<a name="read-text-file-portion"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(read-text-file-portion input-port portion)</span>
  <span class="comment">; read up to portion characters from input-port</span><br /> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">str</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX375" title="R5RS Scheme form">make-string</a> portion #\space)))
  (<a class="applied-name" href="file-read-1.html#read-into-string" title="file-read">read-into-string</a> input-port str 0 portion)))

<a name="read-into-string"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(read-into-string input-port str position max)</span>
  <span class="comment">; read up to max characters into str in a tail recursive fashion.
; return the string</span><br /> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> position max)
     str
     (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">ch</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX451" title="R5RS Scheme form">read-char</a> input-port)))
       (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX455" title="R5RS Scheme form">eof-object?</a> ch) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> str 0 position))
	      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX125" title="R5RS Scheme form">begin</a>
	              (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX380" title="R5RS Scheme form">string-set!</a> str position ch)
	              (<a class="applied-name" href="file-read-1.html#read-into-string" title="file-read">read-into-string</a> input-port str (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> position 1) max)))))))

<a name="state-list"></a><span class="comment">; -----------------------------------------------------------------------------
; File reading between marks.</span><br />
<a name="state-list"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">state-list</span> '()) <a name="debugging-with-marks"></a><span class="comment">; for debugging purposes</span><br /><a name="debugging-with-marks"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">debugging-with-marks</span> #f)

<a name="read-text-file-between-marks"></a><span><a href="../file-read.html#read-text-file-between-marks"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(read-text-file-between-marks file-name mark)</span>
  <div class="schemedoc-definition-comment">;; Reads the part of the file between - but excluding - two occurences of mark, and return it as a text string. 
;; Specifically, it read and return the string from, but excluding, the first occurence of mark
;; to, but excluding, the next occurence of mark.
;; If no occurence of mark can be located, return the empty string.
;; If only one occurence of mark occurs, return a suffix of the file from the mark to the end of file.
;; This function is implemented by means of a state machine which controls when the actual reading must take place.</div> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="file-read-1.html#current-state" title="file-read">current-state</a> 'skip)
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> <a class="applied-name" href="file-read-1.html#debugging-with-marks" title="file-read">debugging-with-marks</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="file-read-1.html#state-list" title="file-read">state-list</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX332" title="R5RS Scheme form">list</a> 'skip)))
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">ip</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX444" title="R5RS Scheme form">open-input-file</a> file-name))
        (<span class="local-name-binding">res</span> (<a class="applied-name" href="file-read-1.html#read-text-file-from-input-port-with-marks" title="file-read">read-text-file-from-input-port-with-marks</a> ip mark)))
     (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX446" title="R5RS Scheme form">close-input-port</a> ip)
     (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="file-read-1.html#current-state" title="file-read">current-state</a> 'skip)
     res))

<a name="file-chunck-with-marks"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">file-chunck-with-marks</span> 1000)
<a name="current-state"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">current-state</span> 'skip)

<a name="read-text-file-from-input-port-with-marks"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(read-text-file-from-input-port-with-marks input-port mark)</span>
  <span class="comment">; return the textual contents of file-name, as a string</span><br /> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">res</span> (<a class="applied-name" href="file-read-1.html#read-text-file-portion-with-marks" title="file-read">read-text-file-portion-with-marks</a> input-port <a class="applied-name" href="file-read-1.html#file-chunck-with-marks" title="file-read">file-chunck-with-marks</a> mark)))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX455" title="R5RS Scheme form">eof-object?</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX453" title="R5RS Scheme form">peek-char</a> input-port)))
      (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> res (<a class="applied-name" href="file-read-1.html#read-text-file-from-input-port-with-marks" title="file-read">read-text-file-from-input-port-with-marks</a> input-port mark))
      res)))

<a name="read-text-file-portion-with-marks"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(read-text-file-portion-with-marks input-port portion mark)</span>
  <span class="comment">; read up to portion characters from input-port</span><br /> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">str</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX375" title="R5RS Scheme form">make-string</a> portion #\space)))
  (<a class="applied-name" href="file-read-1.html#read-into-string-with-marks" title="file-read">read-into-string-with-marks</a> input-port str 0 portion mark)))

<a name="read-into-string-with-marks"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(read-into-string-with-marks input-port str position max mark)</span>
<span class="comment">; read up to max characters into str in a tail recursive fashion. Return the string.</span><br />  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> position max)
      str
      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">ch</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX451" title="R5RS Scheme form">read-char</a> input-port)))
	(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX455" title="R5RS Scheme form">eof-object?</a> ch) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> str 0 position))
	      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">trans-result</span> (<a class="applied-name" href="file-read-1.html#transition" title="file-read">transition</a> <a class="applied-name" href="file-read-1.html#current-state" title="file-read">current-state</a> ch mark))
			   (<span class="local-name-binding">next-state</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> trans-result))
			   (<span class="local-name-binding">output-function</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> trans-result))
			   (<span class="local-name-binding">output-string</span> (output-function <a class="applied-name" href="file-read-1.html#current-state" title="file-read">current-state</a> next-state ch mark)))
                      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> <a class="applied-name" href="file-read-1.html#debugging-with-marks" title="file-read">debugging-with-marks</a>
                          (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="file-read-1.html#state-list" title="file-read">state-list</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> next-state <a class="applied-name" href="file-read-1.html#state-list" title="file-read">state-list</a>)))
		      (<a class="applied-name" href="file-read-1.html#put-into-string!" title="file-read">put-into-string!</a> str position output-string)
                      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="file-read-1.html#current-state" title="file-read">current-state</a> next-state)
		      (<a class="applied-name" href="file-read-1.html#read-into-string-with-marks" title="file-read">read-into-string-with-marks</a> input-port str (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> position (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> output-string)) max mark)))))))

<a name="put-into-string!"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(put-into-string! str position addition)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> addition) 0)
      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX125" title="R5RS Scheme form">begin</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX380" title="R5RS Scheme form">string-set!</a> str position (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> addition 0))
             (<a class="applied-name" href="file-read-1.html#put-into-string!" title="file-read">put-into-string!</a> str (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> 1 position) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> addition 1 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> addition))))))

<span class="comment">; -------------------------------------------------
; The state machine controlling the reading process between marks
; The marks are not included in the text returned</span><br />
<a name="output-skip"></a><span class="comment">; States are either a symbol or a number:
;   The symbol skip: Do not collect the character read.
;   The symbol skip-rest: Reading is done. Never collect more characters.
;                         (prevents re-reading after marked region).           
;   The symbol collect: Do collect the character read.
;   A positive number n: We have recognized n characters of the mark
;                        from a skipping state towards a collecting state
;   A negative number n: We have recognized -n characters of the mark
;                        from collecting state towards a skipping state.
;
; Observation: In negatively numbered states, we have to output a partially
; matched mark. This is done by output-pending-mark.</span><br />

<a name="output-skip"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(output-skip in-state out-state char mark)</span>
  "")

<a name="output-let-go"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(output-let-go in-state out-state char mark)</span> 
  (<a class="schemedoc-name" href="../../../lib/man/general.html#as-string" title="Manual: general">as-string</a> char))

<a name="output-pending-mark"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(output-pending-mark in-state out-state char mark)</span>
  <span class="comment">; output the portion of the mark already read</span><br />  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> mark 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX257" title="R5RS Scheme form">abs</a> in-state)))


<a name="transition"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(transition in-state char mark)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">mark0</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> mark 0)))  <span class="comment">; first char in mark</span><br />    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a>  ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX346" title="R5RS Scheme form">symbol?</a> in-state) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX199" title="R5RS Scheme form">eq?</a> in-state 'skip))
              (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX196" title="R5RS Scheme form">eqv?</a> char mark0)                            (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> 1 <a class="applied-name" href="file-read-1.html#output-skip" title="file-read">output-skip</a>))
                    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a>                                        (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> 'skip <a class="applied-name" href="file-read-1.html#output-skip" title="file-read">output-skip</a>))))

           ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX346" title="R5RS Scheme form">symbol?</a> in-state) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX199" title="R5RS Scheme form">eq?</a> in-state 'collect))     
              (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX196" title="R5RS Scheme form">eqv?</a> char mark0)                            (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> -1 <a class="applied-name" href="file-read-1.html#output-skip" title="file-read">output-skip</a>))
                    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a>                                        (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> 'collect <a class="applied-name" href="file-read-1.html#output-let-go" title="file-read">output-let-go</a>))))

           ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="applied-name" href="file-read-1.html#positive-number?" title="file-read">positive-number?</a> in-state) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX236" title="R5RS Scheme form">&lt;</a> in-state (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> mark))
              (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX196" title="R5RS Scheme form">eqv?</a> char (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> mark in-state))       
                                                                 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> in-state 1) <a class="applied-name" href="file-read-1.html#output-skip" title="file-read">output-skip</a>))
                    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a>                                        (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> 'skip <a class="applied-name" href="file-read-1.html#output-skip" title="file-read">output-skip</a>)))))

           ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="applied-name" href="file-read-1.html#positive-number?" title="file-read">positive-number?</a> in-state) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> in-state (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> mark)))
                                                                 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> 'collect <a class="applied-name" href="file-read-1.html#output-let-go" title="file-read">output-let-go</a>))

           ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="applied-name" href="file-read-1.html#negative-number?" title="file-read">negative-number?</a> in-state) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX236" title="R5RS Scheme form">&lt;</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX257" title="R5RS Scheme form">abs</a> in-state) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> mark)))
              (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX196" title="R5RS Scheme form">eqv?</a> char (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> mark (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX257" title="R5RS Scheme form">abs</a> in-state)))       
                                                                 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> in-state 1) <a class="applied-name" href="file-read-1.html#output-skip" title="file-read">output-skip</a>))
                    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a>                                        (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> 'collect <a class="applied-name" href="file-read-1.html#output-pending-mark" title="file-read">output-pending-mark</a>))))

           ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="applied-name" href="file-read-1.html#negative-number?" title="file-read">negative-number?</a> in-state) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX257" title="R5RS Scheme form">abs</a> in-state) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> mark)))
                                                                 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> 'skip-rest <a class="applied-name" href="file-read-1.html#output-skip" title="file-read">output-skip</a>))

           ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX346" title="R5RS Scheme form">symbol?</a> in-state) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX199" title="R5RS Scheme form">eq?</a> in-state 'skip-rest))   (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> 'skip-rest <a class="applied-name" href="file-read-1.html#output-skip" title="file-read">output-skip</a>))

       )))

<a name="positive-number?"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(positive-number? x)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX224" title="R5RS Scheme form">number?</a> x) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> x 0)))


<a name="negative-number?"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(negative-number? x)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX224" title="R5RS Scheme form">number?</a> x) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX236" title="R5RS Scheme form">&lt;</a> x 0)))



<a name="read-text-file-including-marks"></a><span class="comment">; -----------------------------------------------------------------------------
; File reading including start-mark and end-mark
; We support potential different start and end marks</span><br />
<a name="read-text-file-including-marks"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(read-text-file-including-marks file-name start-mark end-mark)</span>
  <div class="schemedoc-definition-comment">;; Reads the part of the file between and including occurences of start-mark and end-mark, and return it as a text string.
;; Specifically, read and return the string from and including the first occurence of start-mark
;; to and including the next occurence of end-mark. 
;; If no occurence of the mark can be located, return the empty string.
;; If only the start-mark occurs, return a suffix of the file from the start-mark to the end of file.
;; This function is implemented by means of a state machine which controls when the actual reading must take place.</div> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="file-read-1.html#current-state" title="file-read">current-state</a> 'skip)
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> <a class="applied-name" href="file-read-1.html#debugging-with-marks" title="file-read">debugging-with-marks</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="file-read-1.html#state-list" title="file-read">state-list</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX332" title="R5RS Scheme form">list</a> 'skip)))
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">ip</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX444" title="R5RS Scheme form">open-input-file</a> file-name))
        (<span class="local-name-binding">res</span> (<a class="applied-name" href="file-read-1.html#read-text-file-from-input-port-including-marks" title="file-read">read-text-file-from-input-port-including-marks</a> ip start-mark end-mark)))
     (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX446" title="R5RS Scheme form">close-input-port</a> ip)
     (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="file-read-1.html#current-state" title="file-read">current-state</a> 'skip)
     res))

<a name="read-text-file-from-input-port-including-marks"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(read-text-file-from-input-port-including-marks input-port start-mark end-mark)</span>
  <span class="comment">; return the textual contents of file-name, as a string</span><br /> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">res</span> (<a class="applied-name" href="file-read-1.html#read-text-file-portion-including-marks" title="file-read">read-text-file-portion-including-marks</a> input-port <a class="applied-name" href="file-read-1.html#file-chunck-with-marks" title="file-read">file-chunck-with-marks</a> start-mark end-mark)))
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX455" title="R5RS Scheme form">eof-object?</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX453" title="R5RS Scheme form">peek-char</a> input-port)))
      (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> res (<a class="applied-name" href="file-read-1.html#read-text-file-from-input-port-including-marks" title="file-read">read-text-file-from-input-port-including-marks</a> input-port start-mark end-mark))
      res)))

<a name="read-text-file-portion-including-marks"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(read-text-file-portion-including-marks input-port portion start-mark end-mark)</span>
  <span class="comment">; read up to portion characters from input-port</span><br /> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">str</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX375" title="R5RS Scheme form">make-string</a> portion #\space)))
  (<a class="applied-name" href="file-read-1.html#read-into-string-including-marks" title="file-read">read-into-string-including-marks</a> input-port str 0 portion start-mark end-mark)))

<a name="read-into-string-including-marks"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(read-into-string-including-marks input-port str position max start-mark end-mark)</span>
<span class="comment">; read up to max characters into str in a tail recursive fashion. Return the string.</span><br />  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> position max)
      str
      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">ch</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX451" title="R5RS Scheme form">read-char</a> input-port)))
	(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX455" title="R5RS Scheme form">eof-object?</a> ch) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> str 0 position))
	      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a> (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">trans-result</span> (<a class="applied-name" href="file-read-1.html#transition1" title="file-read">transition1</a> <a class="applied-name" href="file-read-1.html#current-state" title="file-read">current-state</a> ch start-mark end-mark))
			   (<span class="local-name-binding">next-state</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> trans-result))
			   (<span class="local-name-binding">output-function</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX322" title="R5RS Scheme form">cdr</a> trans-result))
			   (<span class="local-name-binding">output-string</span> (output-function <a class="applied-name" href="file-read-1.html#current-state" title="file-read">current-state</a> next-state ch start-mark end-mark)))
                      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> <a class="applied-name" href="file-read-1.html#debugging-with-marks" title="file-read">debugging-with-marks</a>
                          (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="file-read-1.html#state-list" title="file-read">state-list</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> next-state <a class="applied-name" href="file-read-1.html#state-list" title="file-read">state-list</a>)))
		      (<a class="applied-name" href="file-read-1.html#put-into-string!" title="file-read">put-into-string!</a> str position output-string)
                      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX106" title="R5RS Scheme form">set!</a> <a class="applied-name" href="file-read-1.html#current-state" title="file-read">current-state</a> next-state)
		      (<a class="applied-name" href="file-read-1.html#read-into-string-including-marks" title="file-read">read-into-string-including-marks</a> input-port str (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> position (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> output-string))
                                                        max start-mark end-mark)))))))

<a name="put-into-string!"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(put-into-string! str position addition)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX237" title="R5RS Scheme form">&gt;</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> addition) 0)
      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX125" title="R5RS Scheme form">begin</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX380" title="R5RS Scheme form">string-set!</a> str position (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> addition 0))
             (<a class="applied-name" href="file-read-1.html#put-into-string!" title="file-read">put-into-string!</a> str (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> 1 position) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> addition 1 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> addition))))))

<span class="comment">; -------------------------------------------------
; The state machine controlling the reading process between marks
; The marks are not included in the text returned</span><br />
<a name="output-skip1"></a><span class="comment">; States are either a symbol or a number:
;   The symbol skip: Do not collect the character read.
;   The symbol skip-rest: Reading is done. Never collect more characters.
;                         (prevents re-reading after marked region).           
;   The symbol collect: Do collect the character read.
;   A positive number n: We have recognized n characters of the start mark,
;                        from a skipping state towards a collecting state
;   A negative number n: We have recognized -n characters of the end-mark, 
;                        from collecting state towards a skipping state.
;
; Observation: In negatively numbered states, we have to output a partially
; matched mark. This is done by output-pending-mark.</span><br />

<a name="output-skip1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(output-skip1 in-state out-state char start-mark end-mark)</span>
  "")

<a name="output-let-go1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(output-let-go1 in-state out-state char start-mark end-mark)</span> 
  (<a class="schemedoc-name" href="../../../lib/man/general.html#as-string" title="Manual: general">as-string</a> char))


<a name="output-pending-start-mark"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(output-pending-start-mark in-state out-state char start-mark end-mark)</span>
  <span class="comment">; output the portion of the mark already read</span><br />  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX392" title="R5RS Scheme form">string-append</a> start-mark (<a class="schemedoc-name" href="../../../lib/man/general.html#as-string" title="Manual: general">as-string</a> char)))

<a name="output-pending-end-mark"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(output-pending-end-mark in-state out-state char start-mark end-mark)</span>
  <span class="comment">; output the portion of the mark already read</span><br />  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX391" title="R5RS Scheme form">substring</a> end-mark 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX257" title="R5RS Scheme form">abs</a> in-state)))


<a name="transition1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(transition1 in-state char start-mark end-mark)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">mark0</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> start-mark 0))  <span class="comment">; first char in start-mark</span><br />        (<span class="local-name-binding">markn</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> end-mark 0))    <span class="comment">; first char in end-mark</span><br />       )
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a>  ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX346" title="R5RS Scheme form">symbol?</a> in-state) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX199" title="R5RS Scheme form">eq?</a> in-state 'skip))
              (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX196" title="R5RS Scheme form">eqv?</a> char mark0)                            (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> 1 <a class="applied-name" href="file-read-1.html#output-skip1" title="file-read">output-skip1</a>))
                    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a>                                        (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> 'skip <a class="applied-name" href="file-read-1.html#output-skip1" title="file-read">output-skip1</a>))))

           ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX346" title="R5RS Scheme form">symbol?</a> in-state) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX199" title="R5RS Scheme form">eq?</a> in-state 'collect))     
              (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX196" title="R5RS Scheme form">eqv?</a> char markn)                            (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> -1 <a class="applied-name" href="file-read-1.html#output-let-go1" title="file-read">output-let-go1</a>))
                    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a>                                        (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> 'collect <a class="applied-name" href="file-read-1.html#output-let-go1" title="file-read">output-let-go1</a>))))

           ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="applied-name" href="file-read-1.html#positive-number?" title="file-read">positive-number?</a> in-state) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX236" title="R5RS Scheme form">&lt;</a> in-state (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> start-mark))
              (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX196" title="R5RS Scheme form">eqv?</a> char (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> start-mark in-state))       
                                                                 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> in-state 1) <a class="applied-name" href="file-read-1.html#output-skip1" title="file-read">output-skip1</a>))
                    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a>                                        (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> 'skip <a class="applied-name" href="file-read-1.html#output-skip1" title="file-read">output-skip1</a>)))))

           ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="applied-name" href="file-read-1.html#positive-number?" title="file-read">positive-number?</a> in-state) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> in-state (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> start-mark)))
                                                                 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> 'collect <a class="applied-name" href="file-read-1.html#output-pending-start-mark" title="file-read">output-pending-start-mark</a>))

           ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="applied-name" href="file-read-1.html#negative-number?" title="file-read">negative-number?</a> in-state) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX236" title="R5RS Scheme form">&lt;</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX257" title="R5RS Scheme form">abs</a> in-state) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> end-mark)))
              (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">cond</a> ((<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX196" title="R5RS Scheme form">eqv?</a> char (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> end-mark (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX257" title="R5RS Scheme form">abs</a> in-state)))       
                                                                 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX251" title="R5RS Scheme form">-</a> in-state 1) <a class="applied-name" href="file-read-1.html#output-let-go1" title="file-read">output-let-go1</a>))
                    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX110" title="R5RS Scheme form">else</a>                                        (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> 'collect <a class="applied-name" href="file-read-1.html#output-let-go1" title="file-read">output-let-go1</a>))))

           ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="applied-name" href="file-read-1.html#negative-number?" title="file-read">negative-number?</a> in-state) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX235" title="R5RS Scheme form">=</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX257" title="R5RS Scheme form">abs</a> in-state) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> end-mark)))
                                                                 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> 'skip-rest <a class="applied-name" href="file-read-1.html#output-skip1" title="file-read">output-skip1</a>))

           ((<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX117" title="R5RS Scheme form">and</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX346" title="R5RS Scheme form">symbol?</a> in-state) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX199" title="R5RS Scheme form">eq?</a> in-state 'skip-rest))   (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX320" title="R5RS Scheme form">cons</a> 'skip-rest <a class="applied-name" href="file-read-1.html#output-skip1" title="file-read">output-skip1</a>))

       )))


<span class="comment">; ---------------------------------------------------------------------------------------------------------------</span><br />
<a name="code-example"></a><div class="schemedoc-definition-comment">;; Convenient and specialized function returning the contents of a program file.
;; Other usages are also possible.
;; Reads an external file, either an entire file (if no optional mark parameter)
;; or a region surrounded by mark.</div>
<a name="code-example"></a><span><a href="../file-read.html#code-example"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(code-example file . mark)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">code-text</span>
           (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX330" title="R5RS Scheme form">null?</a> mark) 
               (<a class="applied-name" href="file-read-1.html#read-text-file" title="file-read">read-text-file</a> file)
               (<a class="applied-name" href="file-read-1.html#read-text-file-between-marks" title="file-read">read-text-file-between-marks</a> file (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX321" title="R5RS Scheme form">car</a> mark)))))
     code-text))





<span class="comment">; ---------------------------------------------------------------------------------------------------------------</span><br />
<div class="schemedoc-section-comment">;;; Writing stuff. </div>
<a name="write-text-file"></a><div class="schemedoc-definition-comment">;; Write the text string str to the file named file-name. 
;; After this function call, the file contains exactly the string str.
;; Opening and closing is done by this function.
;; .form (write-text-file str file-name [suppress-cr])
;; .parameter suppress-cr If true, never write a cr (character 13). Ie. never use PC end of line conventions.</div><a name="write-text-file"></a><span><a href="../file-read.html#write-text-file"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(write-text-file str file-name . optional-parameter-list)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">suppress-cr</span> (<a class="schemedoc-name" href="../../../lib/man/general.html#optional-parameter" title="Manual: general">optional-parameter</a> 1 optional-parameter-list #f)))
   (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (file-exists? file-name) (delete-file file-name))
   (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX122" title="R5RS Scheme form">let*</a> ((<span class="local-name-binding">op</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX445" title="R5RS Scheme form">open-output-file</a> file-name)))
     (<a class="applied-name" href="file-read-1.html#write-text-file-to-port" title="file-read">write-text-file-to-port</a> str op suppress-cr)
     (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX447" title="R5RS Scheme form">close-output-port</a> op))))

<a name="write-string-to-port"></a><div class="schemedoc-definition-comment">;; Write the string str to port, which is assumed to be open.
;; This procedure does not close the port.
;; .form (write-string-to-port str port [suppress-cr])
;; .parameter suppress-cr If true, never write a cr (character 13). Ie. never use PC end of line conventions.
;; .internal-references "similar function" "write-port-strings"</div><a name="write-string-to-port"></a><span><a href="../file-read.html#write-string-to-port"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(write-string-to-port str port . optional-parameter-list)</span>
 (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">suppress-cr</span> (<a class="schemedoc-name" href="../../../lib/man/general.html#optional-parameter" title="Manual: general">optional-parameter</a> 1 optional-parameter-list #f)))
  (<a class="applied-name" href="file-read-1.html#write-text-file-to-port" title="file-read">write-text-file-to-port</a> str port suppress-cr)))

<a name="write-port-strings"></a><div class="schemedoc-definition-comment">;; Write each of the strings in the parameter strings to port.
;; The output port port is assumed to be open.
;; This procedure does not close the port.
;; .parameter port An open output port
;; .parameter strings A list of strings (a rest parameter of the function).
;; .internal-references "similar function" "write-string-to-port"
;; .misc Notice the order of the parameters compared with write-string-to-port.</div><a name="write-port-strings"></a><span><a href="../file-read.html#write-port-strings"><img src="../../../images/elucidator/small-prev.gif" title="SchemeDoc Manual entry" alt="" border="0" /></a> <br /></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(write-port-strings port . strings)</span>
  (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX413" title="R5RS Scheme form">for-each</a>
     (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX98" title="R5RS Scheme form">lambda</a> (<span class="local-name-binding">str</span>) (<a class="applied-name" href="file-read-1.html#write-string-to-port" title="file-read">write-string-to-port</a> str port))
     strings))

<a name="write-text-file-to-port"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(write-text-file-to-port str port suppress-cr)</span>
  (<a class="applied-name" href="file-read-1.html#write-text-file-to-port-1" title="file-read">write-text-file-to-port-1</a> 0 (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX378" title="R5RS Scheme form">string-length</a> str) str port suppress-cr))

<a name="write-text-file-to-port-1"></a><span></span>(<a class="scheme-syntax-name" href="../../../r5rs/r5rs_7.html#IDX173" title="R5RS Scheme form">define</a> <span class="signature">(write-text-file-to-port-1 i max str port suppress-cr)</span>
  (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX236" title="R5RS Scheme form">&lt;</a> i max)
    (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX125" title="R5RS Scheme form">begin</a>
      (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX121" title="R5RS Scheme form">let</a> ((<span class="local-name-binding">ch</span> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX379" title="R5RS Scheme form">string-ref</a> str i)))
       (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> suppress-cr
           (<a class="scheme-syntax-name" href="../../../r5rs/r5rs_6.html#IDX103" title="R5RS Scheme form">if</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX304" title="R5RS Scheme form">not</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX196" title="R5RS Scheme form">eqv?</a> ch #\return)) (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX466" title="R5RS Scheme form">write-char</a> ch port))
           (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX466" title="R5RS Scheme form">write-char</a> ch port))
       (<a class="applied-name" href="file-read-1.html#write-text-file-to-port-1" title="file-read">write-text-file-to-port-1</a> (<a class="scheme-procedure-name" href="../../../r5rs/r5rs_8.html#IDX249" title="R5RS Scheme form">+</a> i 1) max str port suppress-cr)))))
  

</pre></font><div>&nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p> &nbsp; <p></p></div></body></html>